import Vue from 'vue'
import Router from 'vue-router'

import Login from '@/views/login'
import Layout from '@/layout/layout'

Vue.use(Router)

/**
 * alwaysShow: true           if set true, will always show the root menu, whatever its child routes length
 *                            if not set alwaysShow, only more than ont route under the children
 *                            it will becomes nested mode, otherwise not show the root menu
 * alwaysShow: true           如果设置为true,它将总是现在在根目录。如果不设置的话，当它只有1个子路由的时候，会把
 *                            它的唯一子路由放到跟目录上来，而不显示它自己本身。
 */
const TEACHER=['2']
const  ADMIN=['0']
const STUDENT=['1']

export const constantRouterMap = [
  {
    path: '/login',
    name: 'login',
    hidden: true,
    component: Login,
    meta: {
      title: '登录',
      requireAuth:false
    }
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true,
    meta:{
      title:'404',
      requireAuth:false
    }
  },
  {
    path: '/',
    hidden: true,
    component: Layout,
    redirect: '/home',
    meta: {title: '首页',
      requireAuth:true,
      permissionCode:STUDENT.concat(TEACHER).concat(ADMIN)
    },
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/homepage'),
        meta: {title: '首页',
          requireAuth:true,
          permissionCode:STUDENT.concat(TEACHER).concat(ADMIN)
        }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    meta: {
      icon: 'tickets',
      title: '个人中心',
      requireAuth:true,
      permissionCode:STUDENT.concat(TEACHER).concat(ADMIN)
    },
    children: [
      {
        path: 'profile',
        name: 'Profile',
        component: () => import('@/views/user/profile'),
        meta: {icon: 'warning', title: '个人中心',
          requireAuth:true,
          permissionCode:STUDENT.concat(TEACHER).concat(ADMIN)}
      },
      {
        path: 'avatar',
        name: 'Avatar',
        component: () => import('@/views/user/profile'),
        meta: {icon: 'warning', title: '修改头像',
          requireAuth:true,
          permissionCode:STUDENT.concat(TEACHER).concat(ADMIN)}
      }
    ]
  },
  {
    path: '/user-manage',
    component: Layout,
    redirect: '/introduction/index',
    // alwaysShow: true,
    meta: {
      icon: 'user-solid',
      title: '用户管理',
      requireAuth:true,
      permissionCode:ADMIN
    },
    children: [
      {
        path: 'index',
        name: 'Introduction',
        component: () => import('@/views/user-manage/'),
        meta: {icon: 'user-solid', title: '用户列表',
          requireAuth:true,
          permissionCode:ADMIN
        }
      }
    ]
  },
  {
    path: '/course-manage',
    component: Layout,
    redirect: 'index',
    meta: {
      title: '课程管理',
      icon: 'svg-droplet',
      permissionCode:ADMIN.concat(STUDENT).concat(TEACHER).concat(STUDENT)
    },
    children: [
      {
        path: 'index',
        name: '课程列表',
        component: () => import('@/views/course-manage'),
        meta: {title: '课程列表', icon: 'svg-heart',
          requireAuth:true,
          permissionCode:ADMIN.concat(STUDENT).concat(TEACHER)} // 都可见，但是要用不同组件展示
      },
      {
        path: 'publish',
        name: '课程发布',
        component: () => import('@/views/course-manage/Publish'),
        meta: {title: '课程发布', icon: 'circle-plus',
          requireAuth:true,
          permissionCode:ADMIN.concat(TEACHER)} //只有管理员和教师可见
      }
    ]
  },
  //考勤管理
  {
    path: '/attendance-manage',
    component: Layout,
    alwaysShow: true,
    meta: {
      icon: 's-order',
      title: '考勤管理',
      requireAuth:true,
      permissionCode:ADMIN.concat(TEACHER).concat(STUDENT)
    },
    children: [
      {
        path: 'attendance-list-admin-teacher',
        name: 'attendance-list-admin-teacher',
        component: () => import('@/views/attendance-manage'),
        meta: {icon: 's-order', title: '考勤列表',
          permissionCode:ADMIN.concat(TEACHER)} //管理员和教师可进
      },
      {
        path: 'attendance-student',
        name: 'attendance-student',
        component: () => import('@/views/attendance-manage'),//只有学生可进
        meta: {icon: 'svg-type', title: '我的考勤',
          permissionCode:STUDENT}
      },
      {
        path: 'attendance-student-start',//开始考勤
        name: 'attendance-student-start',
        component: () => import('@/views/attendance-manage/StartCamera'),//只有学生可进
        meta: {icon: 'message-solid', title: '开始考勤',
          permissionCode:STUDENT}
      },
      {
        path: 'publish-attendance',
        name: 'publish-attendance',
        component: () => import('@/views/attendance-manage/publish'),//只有教师可进
        meta: {icon: 'svg-type', title: '发布考勤',
          permissionCode:TEACHER}
      },

    ]
  },
  {
    path: '/leave-manage',
    component: Layout,
    alwaysShow: true,
    meta: {
      icon: 's-grid',
      title: '请假管理',
      requireAuth:true,
      permissionCode:ADMIN.concat(TEACHER).concat(STUDENT)
    },
    children: [
      {
        path: 'leave-list',
        name: 'draggable1',
        component: () => import('@/views/futures/'),
        meta: {icon: 'thumb', title: '请假列表',
          permissionCode:ADMIN.concat(TEACHER)} //教师和管理员可见
      },
      {
        path: 'leave-student',
        name: 'draggable2',
        component: () => import('@/views/futures/StudentLeaveList'),
        meta: {icon: 'thumb', title: '我的请假',
          permissionCode:STUDENT} //学生可见
      },
      {
        path: 'publish',
        name: 'draggable3',
        component: () => import('@/views/futures/PublishLeave'),
        meta: {icon: 'edit', title: '新建请假',
          permissionCode:STUDENT} //学生可见
      },

    ]
  },
  {
    path: '/face-manage',
    component: Layout,
    meta: {
      icon: 's-custom',
      title: '人脸管理',
      requireAuth:true,
      permissionCode:ADMIN
    },
    children: [
      {
        path: 'index',
        name: 'face-manage-admin',
        component: () => import('@/views/Face-Manage/'),
        meta: {icon: 's-custom', title: '人脸管理',
          permissionCode:ADMIN} //管理员可见（包含人脸增删改查）
      },
    ]
  }
]

export default new Router({
  // mode: 'history',  require service support
  // scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

const asyncRouterMap = [
  {
    path: '/excel',
    component: Layout,
    redirect: '/excel/export-excel',
    alwaysShow: true,
    hidden:true,
    meta: {
      title: '表格',
      icon: 'date'
    },
    children: [
      {
        path: 'export-excel',
        name: '导出表格',
        hidden:true,
        component: () => import('@/views/excel/export-excel'),
        meta: {icon: 'download', title: '导出表格'}
      },
      {
        path: 'upload-excel',
        name: '上传表格',
        hidden:true,
        component: () => import('@/views/excel/upload-excel'),
        meta: {icon: 'upload', title: '上传表格'}
      },
      {
        path: 'merge-count',
        name: '合并&统计',
        hidden:true,
        component: () => import('@/views/excel/merge-count'),
        meta: {icon: 'upload', title: '合并&统计'}
      }
    ]
  },
  {
    path: '/clipboard',
    component: Layout,
    redirect: 'index',
    hidden:true,
    meta: {
      icon: 'document',
      title: '剪切板'
    },
    children: [
      {
        path: 'index',
        name: 'clipBoard',
        component: () => import('@/views/clipboard'),
        meta: {title: '剪切板示例', icon: 'document'},
        hidden:true,
      }
    ]
  },
  {
    path: '/theme',
    component: Layout,
    hidden:true,
    meta: {
      icon: 'document',
      title: 'theme'
    },
    children: [
      {
        path: 'index',
        hidden:true,
        component: () => import('@/views/theme/index'),
        name: 'Theme',
        meta: { title: '主题', icon: 'svg-pifu' }
      }
    ]
  },
  {
    path: '/test',
    component: Layout,
    hidden:true,
    meta: {
      icon: 'document',
      title: '测试用例'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/test/index'),
        name: 'Test',
        meta: { title: '测试', icon: 'document' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
